<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>window.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-dialogs-findfiles-example.html">Find Files Example</a></td><td >window.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">window.cpp 示例文件</h1>
<span class="subtitle">dialogs/findfiles/window.cpp</span>
<!-- $$$dialogs/findfiles/window.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the examples of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &lt;QtWidgets&gt;</span>

  <span class="preprocessor">#include &quot;window.h&quot;</span>

  <span class="keyword">enum</span> { absoluteFileNameRole <span class="operator">=</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>UserRole <span class="operator">+</span> <span class="number">1</span> };

  <span class="keyword">static</span> <span class="keyword">inline</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileNameOfItem(<span class="keyword">const</span> <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span> <span class="operator">*</span>item)
  {
      <span class="keyword">return</span> item<span class="operator">-</span><span class="operator">&gt;</span>data(absoluteFileNameRole)<span class="operator">.</span>toString();
  }

  <span class="keyword">static</span> <span class="keyword">inline</span> <span class="type">void</span> openFile(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>fileName)
  {
      <span class="type"><a href="../qtgui/qdesktopservices.html">QDesktopServices</a></span><span class="operator">::</span>openUrl(<span class="type"><a href="../qtcore/qurl.html">QUrl</a></span><span class="operator">::</span>fromLocalFile(fileName));
  }

  Window<span class="operator">::</span>Window(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
      : <span class="type"><a href="qwidget.html">QWidget</a></span>(parent)
  {
      setWindowTitle(tr(<span class="string">&quot;Find Files&quot;</span>));
      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>browseButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">&quot;&amp;Browse...&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      connect(browseButton<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Window<span class="operator">::</span>browse);
      findButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">&quot;&amp;Find&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      connect(findButton<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Window<span class="operator">::</span>find);

      fileComboBox <span class="operator">=</span> createComboBox(tr(<span class="string">&quot;*&quot;</span>));
      connect(fileComboBox<span class="operator">-</span><span class="operator">&gt;</span>lineEdit()<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qlineedit.html">QLineEdit</a></span><span class="operator">::</span>returnPressed<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Window<span class="operator">::</span>animateFindClick);
      textComboBox <span class="operator">=</span> createComboBox();
      connect(textComboBox<span class="operator">-</span><span class="operator">&gt;</span>lineEdit()<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qlineedit.html">QLineEdit</a></span><span class="operator">::</span>returnPressed<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Window<span class="operator">::</span>animateFindClick);
      directoryComboBox <span class="operator">=</span> createComboBox(<span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>toNativeSeparators(<span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>currentPath()));
      connect(directoryComboBox<span class="operator">-</span><span class="operator">&gt;</span>lineEdit()<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qlineedit.html">QLineEdit</a></span><span class="operator">::</span>returnPressed<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Window<span class="operator">::</span>animateFindClick);

      filesFoundLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>;

      createFilesTable();

      <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>mainLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>(<span class="keyword">this</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(<span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Named:&quot;</span>))<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fileComboBox<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(<span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Containing text:&quot;</span>))<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(textComboBox<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(<span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;In directory:&quot;</span>))<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(directoryComboBox<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">1</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(browseButton<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">2</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(filesTable<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">3</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(filesFoundLabel<span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(findButton<span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="number">2</span>);

      connect(<span class="keyword">new</span> <span class="type"><a href="qshortcut.html">QShortcut</a></span>(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Quit<span class="operator">,</span> <span class="keyword">this</span>)<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qshortcut.html">QShortcut</a></span><span class="operator">::</span>activated<span class="operator">,</span>
          <a href="qapplication.html#qApp">qApp</a><span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>quit);
  }

  <span class="type">void</span> Window<span class="operator">::</span>browse()
  {
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> directory <span class="operator">=</span>
          <span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>toNativeSeparators(<span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>getExistingDirectory(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">&quot;Find Files&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>currentPath()));

      <span class="keyword">if</span> (<span class="operator">!</span>directory<span class="operator">.</span>isEmpty()) {
          <span class="keyword">if</span> (directoryComboBox<span class="operator">-</span><span class="operator">&gt;</span>findText(directory) <span class="operator">=</span><span class="operator">=</span> <span class="operator">-</span><span class="number">1</span>)
              directoryComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(directory);
          directoryComboBox<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(directoryComboBox<span class="operator">-</span><span class="operator">&gt;</span>findText(directory));
      }
  }

  <span class="keyword">static</span> <span class="type">void</span> updateComboBox(<span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>comboBox)
  {
      <span class="keyword">if</span> (comboBox<span class="operator">-</span><span class="operator">&gt;</span>findText(comboBox<span class="operator">-</span><span class="operator">&gt;</span>currentText()) <span class="operator">=</span><span class="operator">=</span> <span class="operator">-</span><span class="number">1</span>)
          comboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(comboBox<span class="operator">-</span><span class="operator">&gt;</span>currentText());
  }

  <span class="type">void</span> Window<span class="operator">::</span>find()
  {
      filesTable<span class="operator">-</span><span class="operator">&gt;</span>setRowCount(<span class="number">0</span>);

      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileName <span class="operator">=</span> fileComboBox<span class="operator">-</span><span class="operator">&gt;</span>currentText();
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> text <span class="operator">=</span> textComboBox<span class="operator">-</span><span class="operator">&gt;</span>currentText();
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> path <span class="operator">=</span> <span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>cleanPath(directoryComboBox<span class="operator">-</span><span class="operator">&gt;</span>currentText());
      currentDir <span class="operator">=</span> <span class="type"><a href="../qtcore/qdir.html">QDir</a></span>(path);

      updateComboBox(fileComboBox);
      updateComboBox(textComboBox);
      updateComboBox(directoryComboBox);

      <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> filter;
      <span class="keyword">if</span> (<span class="operator">!</span>fileName<span class="operator">.</span>isEmpty())
          filter <span class="operator">&lt;</span><span class="operator">&lt;</span> fileName;
      <span class="type"><a href="../qtcore/qdiriterator.html">QDirIterator</a></span> it(path<span class="operator">,</span> filter<span class="operator">,</span> <span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>AllEntries <span class="operator">|</span> <span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>NoSymLinks <span class="operator">|</span> <span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>NoDotAndDotDot<span class="operator">,</span> <span class="type"><a href="../qtcore/qdiriterator.html">QDirIterator</a></span><span class="operator">::</span>Subdirectories);
      <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> files;
      <span class="keyword">while</span> (it<span class="operator">.</span>hasNext())
          files <span class="operator">&lt;</span><span class="operator">&lt;</span> it<span class="operator">.</span>next();
      <span class="keyword">if</span> (<span class="operator">!</span>text<span class="operator">.</span>isEmpty())
          files <span class="operator">=</span> findFiles(files<span class="operator">,</span> text);
      files<span class="operator">.</span>sort();
      showFiles(files);
  }

  <span class="type">void</span> Window<span class="operator">::</span>animateFindClick()
  {
      findButton<span class="operator">-</span><span class="operator">&gt;</span>animateClick();
  }

  <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> Window<span class="operator">::</span>findFiles(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> <span class="operator">&amp;</span>files<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>text)
  {
      <span class="type"><a href="qprogressdialog.html">QProgressDialog</a></span> progressDialog(<span class="keyword">this</span>);
      progressDialog<span class="operator">.</span>setCancelButtonText(tr(<span class="string">&quot;&amp;Cancel&quot;</span>));
      progressDialog<span class="operator">.</span>setRange(<span class="number">0</span><span class="operator">,</span> files<span class="operator">.</span>size());
      progressDialog<span class="operator">.</span>setWindowTitle(tr(<span class="string">&quot;Find Files&quot;</span>));

      <span class="type"><a href="../qtcore/qmimedatabase.html">QMimeDatabase</a></span> mimeDatabase;
      <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> foundFiles;

      <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> files<span class="operator">.</span>size(); <span class="operator">+</span><span class="operator">+</span>i) {
          progressDialog<span class="operator">.</span>setValue(i);
          progressDialog<span class="operator">.</span>setLabelText(tr(<span class="string">&quot;Searching file number %1 of %n...&quot;</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> files<span class="operator">.</span>size())<span class="operator">.</span>arg(i));
          <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>processEvents();

          <span class="keyword">if</span> (progressDialog<span class="operator">.</span>wasCanceled())
              <span class="keyword">break</span>;

          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileName <span class="operator">=</span> files<span class="operator">.</span>at(i);
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qmimetype.html">QMimeType</a></span> mimeType <span class="operator">=</span> mimeDatabase<span class="operator">.</span>mimeTypeForFile(fileName);
          <span class="keyword">if</span> (mimeType<span class="operator">.</span>isValid() <span class="operator">&amp;</span><span class="operator">&amp;</span> <span class="operator">!</span>mimeType<span class="operator">.</span>inherits(<span class="type"><a href="../qtcore/qstring.html#QStringLiteral">QStringLiteral</a></span>(<span class="string">&quot;text/plain&quot;</span>))) {
              <a href="../qtcore/qtglobal.html#qWarning">qWarning</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Not searching binary file &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>toNativeSeparators(fileName);
              <span class="keyword">continue</span>;
          }
          <span class="type"><a href="../qtcore/qfile.html">QFile</a></span> file(fileName);
          <span class="keyword">if</span> (file<span class="operator">.</span>open(<span class="type"><a href="../qtcore/qiodevice.html">QIODevice</a></span><span class="operator">::</span>ReadOnly)) {
              <span class="type"><a href="../qtcore/qstring.html">QString</a></span> line;
              <span class="type"><a href="../qtcore/qtextstream.html">QTextStream</a></span> in(<span class="operator">&amp;</span>file);
              <span class="keyword">while</span> (<span class="operator">!</span>in<span class="operator">.</span>atEnd()) {
                  <span class="keyword">if</span> (progressDialog<span class="operator">.</span>wasCanceled())
                      <span class="keyword">break</span>;
                  line <span class="operator">=</span> in<span class="operator">.</span>readLine();
                  <span class="keyword">if</span> (line<span class="operator">.</span>contains(text<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>CaseInsensitive)) {
                      foundFiles <span class="operator">&lt;</span><span class="operator">&lt;</span> files<span class="operator">[</span>i<span class="operator">]</span>;
                      <span class="keyword">break</span>;
                  }
              }
          }
      }
      <span class="keyword">return</span> foundFiles;
  }

  <span class="type">void</span> Window<span class="operator">::</span>showFiles(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> <span class="operator">&amp;</span>paths)
  {
      <span class="keyword">for</span> (<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>filePath : paths) {
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> toolTip <span class="operator">=</span> <span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>toNativeSeparators(filePath);
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> relativePath <span class="operator">=</span> <span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>toNativeSeparators(currentDir<span class="operator">.</span>relativeFilePath(filePath));
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qtglobal.html#qint64-typedef">qint64</a></span> size <span class="operator">=</span> <span class="type"><a href="../qtcore/qfileinfo.html">QFileInfo</a></span>(filePath)<span class="operator">.</span>size();
          <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span> <span class="operator">*</span>fileNameItem <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span>(relativePath);
          fileNameItem<span class="operator">-</span><span class="operator">&gt;</span>setData(absoluteFileNameRole<span class="operator">,</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span>(filePath));
          fileNameItem<span class="operator">-</span><span class="operator">&gt;</span>setToolTip(toolTip);
          fileNameItem<span class="operator">-</span><span class="operator">&gt;</span>setFlags(fileNameItem<span class="operator">-</span><span class="operator">&gt;</span>flags() <span class="operator">^</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>ItemIsEditable);
          <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span> <span class="operator">*</span>sizeItem <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span>(<span class="type"><a href="../qtcore/qlocale.html">QLocale</a></span>()<span class="operator">.</span>formattedDataSize(size));
          sizeItem<span class="operator">-</span><span class="operator">&gt;</span>setData(absoluteFileNameRole<span class="operator">,</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span>(filePath));
          sizeItem<span class="operator">-</span><span class="operator">&gt;</span>setToolTip(toolTip);
          sizeItem<span class="operator">-</span><span class="operator">&gt;</span>setTextAlignment(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AlignRight <span class="operator">|</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AlignVCenter);
          sizeItem<span class="operator">-</span><span class="operator">&gt;</span>setFlags(sizeItem<span class="operator">-</span><span class="operator">&gt;</span>flags() <span class="operator">^</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>ItemIsEditable);

          <span class="type">int</span> row <span class="operator">=</span> filesTable<span class="operator">-</span><span class="operator">&gt;</span>rowCount();
          filesTable<span class="operator">-</span><span class="operator">&gt;</span>insertRow(row);
          filesTable<span class="operator">-</span><span class="operator">&gt;</span>setItem(row<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> fileNameItem);
          filesTable<span class="operator">-</span><span class="operator">&gt;</span>setItem(row<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> sizeItem);
      }
      filesFoundLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;%n file(s) found (Double click on a file to open it)&quot;</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> paths<span class="operator">.</span>size()));
      filesFoundLabel<span class="operator">-</span><span class="operator">&gt;</span>setWordWrap(<span class="keyword">true</span>);
  }

  <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>Window<span class="operator">::</span>createComboBox(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>text)
  {
      <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>comboBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
      comboBox<span class="operator">-</span><span class="operator">&gt;</span>setEditable(<span class="keyword">true</span>);
      comboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(text);
      comboBox<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Expanding<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Preferred);
      <span class="keyword">return</span> comboBox;
  }

  <span class="type">void</span> Window<span class="operator">::</span>createFilesTable()
  {
      filesTable <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtablewidget.html">QTableWidget</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">2</span>);
      filesTable<span class="operator">-</span><span class="operator">&gt;</span>setSelectionBehavior(<span class="type"><a href="qabstractitemview.html">QAbstractItemView</a></span><span class="operator">::</span>SelectRows);

      <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> labels;
      labels <span class="operator">&lt;</span><span class="operator">&lt;</span> tr(<span class="string">&quot;Filename&quot;</span>) <span class="operator">&lt;</span><span class="operator">&lt;</span> tr(<span class="string">&quot;Size&quot;</span>);
      filesTable<span class="operator">-</span><span class="operator">&gt;</span>setHorizontalHeaderLabels(labels);
      filesTable<span class="operator">-</span><span class="operator">&gt;</span>horizontalHeader()<span class="operator">-</span><span class="operator">&gt;</span>setSectionResizeMode(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="qheaderview.html">QHeaderView</a></span><span class="operator">::</span>Stretch);
      filesTable<span class="operator">-</span><span class="operator">&gt;</span>verticalHeader()<span class="operator">-</span><span class="operator">&gt;</span>hide();
      filesTable<span class="operator">-</span><span class="operator">&gt;</span>setShowGrid(<span class="keyword">false</span>);
      filesTable<span class="operator">-</span><span class="operator">&gt;</span>setContextMenuPolicy(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>CustomContextMenu);
      connect(filesTable<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qtablewidget.html">QTableWidget</a></span><span class="operator">::</span>customContextMenuRequested<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Window<span class="operator">::</span>contextMenu);
      connect(filesTable<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qtablewidget.html">QTableWidget</a></span><span class="operator">::</span>cellActivated<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Window<span class="operator">::</span>openFileOfItem);
  }


  <span class="type">void</span> Window<span class="operator">::</span>openFileOfItem(<span class="type">int</span> row<span class="operator">,</span> <span class="type">int</span> <span class="comment">/* column */</span>)
  {
      <span class="keyword">const</span> <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span> <span class="operator">*</span>item <span class="operator">=</span> filesTable<span class="operator">-</span><span class="operator">&gt;</span>item(row<span class="operator">,</span> <span class="number">0</span>);
      openFile(fileNameOfItem(item));
  }


  <span class="type">void</span> Window<span class="operator">::</span>contextMenu(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> <span class="operator">&amp;</span>pos)
  {
      <span class="keyword">const</span> <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span> <span class="operator">*</span>item <span class="operator">=</span> filesTable<span class="operator">-</span><span class="operator">&gt;</span>itemAt(pos);
      <span class="keyword">if</span> (<span class="operator">!</span>item)
          <span class="keyword">return</span>;
      <span class="type"><a href="qmenu.html">QMenu</a></span> menu;
  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>copyAction <span class="operator">=</span> menu<span class="operator">.</span>addAction(<span class="string">&quot;Copy Name&quot;</span>);
  <span class="preprocessor">#endif</span>
      <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>openAction <span class="operator">=</span> menu<span class="operator">.</span>addAction(<span class="string">&quot;Open&quot;</span>);
      <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>action <span class="operator">=</span> menu<span class="operator">.</span>exec(filesTable<span class="operator">-</span><span class="operator">&gt;</span>mapToGlobal(pos));
      <span class="keyword">if</span> (<span class="operator">!</span>action)
          <span class="keyword">return</span>;
      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileName <span class="operator">=</span> fileNameOfItem(item);
      <span class="keyword">if</span> (action <span class="operator">=</span><span class="operator">=</span> openAction)
          openFile(fileName);
  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      <span class="keyword">else</span> <span class="keyword">if</span> (action <span class="operator">=</span><span class="operator">=</span> copyAction)
          <span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>clipboard()<span class="operator">-</span><span class="operator">&gt;</span>setText(<span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>toNativeSeparators(fileName));
  <span class="preprocessor">#endif</span>
  }

</pre>
</div>
<!-- @@@dialogs/findfiles/window.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
